﻿package mortal.game.view.shopMall.shopQQ
{
    import Message.DB.Tables.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.mvc.interfaces.*;

    public class ShopQQPointExchangeWin extends BaseWindow
    {
        protected var _tabBg:GImageBitmap;
        protected var _goodsList:GTileList;
        private var _xufeiMonthBtn:GLoadingButton;
        private var _xufeiYearBtn:GLoadingButton;
        protected var _pageSelecter:PageSelecter;
        private var _type:int;
        private var _vipType:int;
        private var showNum:int = 4;
        private static var _instance:ShopQQPointExchangeWin;

        public function ShopQQPointExchangeWin(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:String = null;
            var _loc_2:String = null;
            super.createDisposedChildrenImpl();
            this._vipType = ParamsConst.instance.enterType;
            this._tabBg = UIFactory.gImageBitmap("", 5, 35, this);
            if (this._vipType == 1)
            {
                _loc_1 = ResFileConst.QQYellowXufeiBtn;
                _loc_2 = ResFileConst.QQYellowYearXufeiBtn;
                this._xufeiMonthBtn = UIFactory.gLoadingButton(_loc_1, 300 - 71, 105 + 21, 110, 34, this);
                this._xufeiYearBtn = UIFactory.gLoadingButton(_loc_2, 400 - 48, 105 + 20, 139, 34, this);
            }
            else
            {
                _loc_1 = ResFileConst.QQBlueKaiTongBtn;
                _loc_2 = ResFileConst.QQBlueYearKaitongBtn;
                this._xufeiMonthBtn = UIFactory.gLoadingButton(_loc_1, 170, 105 + 21, 130, 37, this);
                this._xufeiYearBtn = UIFactory.gLoadingButton(_loc_2, 330, 105 + 20, 159, 37, this);
            }
            this._xufeiMonthBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._xufeiYearBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tabBg.dispose(param1);
            this._tabBg = null;
            this._xufeiMonthBtn.dispose(param1);
            this._xufeiMonthBtn = null;
            this._xufeiYearBtn.dispose(param1);
            this._xufeiYearBtn = null;
            if (this._goodsList)
            {
                this._goodsList.dispose(param1);
                this._goodsList = null;
            }
            if (this._pageSelecter)
            {
                this._pageSelecter.dispose(param1);
                this._pageSelecter = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            if (event.target == this._xufeiMonthBtn)
            {
                GameUtil.gotoQQVipMonthUpgrade();
            }
            else if (event.target == this._xufeiYearBtn)
            {
                GameUtil.gotoQQVipYearUpgrade();
            }
            return;
        }// end function

        private function addPagetSelect() : void
        {
            var _loc_1:GTextFormat = null;
            if (this._pageSelecter == null)
            {
                _loc_1 = GlobalStyle.textFormatBai;
                _loc_1.align = AlignMode.CENTER;
                this._pageSelecter = UIFactory.pageSelecter(339 - 152, 390, this, PageSelecter.CompleteMode);
                this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
                this._pageSelecter.pageTextBoxSize = 50;
                this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            }
            this._pageSelecter.currentPage = 1;
            return;
        }// end function

        private function removePageSelect() : void
        {
            if (this._pageSelecter)
            {
                this._pageSelecter.dispose();
                this._pageSelecter = null;
            }
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateItem();
            return;
        }// end function

        private function updateItem() : void
        {
            var _loc_3:TTencentShop = null;
            var _loc_6:Object = null;
            var _loc_1:* = ShopQQConfig.instance.getItemListByType(this._type);
            var _loc_2:* = new DataProvider();
            var _loc_4:* = this._pageSelecter == null || this._pageSelecter.currentPage * this.showNum > _loc_1.length ? (_loc_1.length) : (this._pageSelecter.currentPage * this.showNum);
            var _loc_5:* = this._pageSelecter == null ? (0) : ((this._pageSelecter.currentPage - 1) * this.showNum);
            var _loc_7:* = _loc_5;
            while (_loc_7 < _loc_4)
            {
                
                _loc_3 = _loc_1[_loc_7];
                _loc_6 = {info:_loc_3, index:_loc_7};
                _loc_2.addItem(_loc_6);
                _loc_7++;
            }
            this._goodsList.dataProvider = _loc_2;
            return;
        }// end function

        public function updateInfo() : void
        {
            if (this._goodsList)
            {
                this._goodsList.dispose();
                this._goodsList = null;
            }
            if (this._type == 1)
            {
                this._goodsList = UIFactory.tileList(11, 166, 510 + 125, 225, this);
                this._goodsList.columnWidth = 123;
                this._goodsList.rowHeight = 225;
                this._goodsList.horizontalGap = 2;
                this._goodsList.verticalGap = 5;
                this._goodsList.setStyle("cellRenderer", ShopQQZuandaRender);
                if (this._vipType == 1)
                {
                    this._tabBg.imgUrl = ImagesConst.shopBuyZuanDaByQQBg_1;
                    this._xufeiMonthBtn.move(300 - 71 + 125, 105 + 21);
                    this._xufeiYearBtn.move(400 - 48 + 125, 105 + 20);
                }
                else
                {
                    this._tabBg.imgUrl = ImagesConst.shopBuyZuanDaByQQBg_2;
                    this._xufeiMonthBtn.move(300 - 71 + 100, 105 + 21);
                    this._xufeiYearBtn.move(400 - 48 + 110, 105 + 20);
                }
            }
            else
            {
                this._goodsList = UIFactory.tileList(11, 166, 510, 220, this);
                this._goodsList.columnWidth = 240;
                this._goodsList.rowHeight = 104;
                this._goodsList.horizontalGap = 8;
                this._goodsList.verticalGap = 5;
                this._goodsList.setStyle("cellRenderer", ShopQQPointExchangeRender);
                if (this._vipType == 1)
                {
                    this._tabBg.imgUrl = ImagesConst.shopBuyItemByQQBg_1;
                    this._xufeiMonthBtn.move(300 - 71, 105 + 21);
                    this._xufeiYearBtn.move(400 - 48, 105 + 20);
                }
                else
                {
                    this._tabBg.imgUrl = ImagesConst.shopBuyItemByQQBg_2;
                    this._xufeiMonthBtn.move(200, 105 + 21);
                    this._xufeiYearBtn.move(340, 105 + 20);
                }
            }
            var _loc_1:* = ShopQQConfig.instance.getItemListByType(this._type);
            var _loc_2:* = Math.ceil(_loc_1.length / this.showNum);
            if (_loc_2 > 1)
            {
                this.addPagetSelect();
                this._pageSelecter.maxPage = _loc_2;
            }
            else
            {
                this.removePageSelect();
            }
            this.updateItem();
            return;
        }// end function

        public function set type(param1:int) : void
        {
            this._type = param1;
            if (this._type == 1)
            {
                this.showNum = 5;
                this.setSize(512 + 125, 415);
                this.title = Language.getString(35550);
            }
            else
            {
                this.showNum = 4;
                this.setSize(512, 415);
                this.title = Language.getString(35551);
            }
            return;
        }// end function

        public static function get instance() : ShopQQPointExchangeWin
        {
            if (_instance == null)
            {
                _instance = new ShopQQPointExchangeWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
